import BaseAd from "../../core/base/BaseAd";
import { ResultCallback, ResultState, SDKLogicState, SDKState } from "../../SDKDefine";

import { registerClass } from "../../../cfw/tools/class_decorator";
import { NativeSelftRenderAd } from "../../native/native";


@registerClass('MiMoSelfRenderAd')
export default class MiMoSelfRenderAd extends BaseAd {
    load(): void {
        throw new Error("Method not implemented.");
    }
    hide(): void {
        throw new Error("Method not implemented.");
    }
    show(): void {
        throw new Error("Method not implemented.");
    }

    protected ad: NativeSelftRenderAd;
    protected click_switch: number = 0;
    protected close_num: number = 0;

    // open(param: { callback: ResultCallback, click_switch: number, close_num: number }) {
    //     this.resultCallback = param.callback;
    //     this.click_switch = param.click_switch;
    //     this.close_num = param.close_num;
    //     this.destroy();
    //     this.create();
    //     this.load();
    // }

    create(): void {
        if (!this.ad) {
            this.ad = this.sdk.createSelfRenderAd({
                adUnitId: this.adUnitID,
                click_switch: this.click_switch,
                close_num: this.close_num

            })
            this.ad.onLoad(this.getFunc(this.onLoad))
            this.ad.onError(this.getFunc(this.onError))
        }
    }

    // load(ls: SDKState = SDKState.open) {
    //     this.logicState = ls;
    //     if (this.instance) {
    //         this.instance.load();
    //     }


    // }
 
    // onLoad() {
    //     // if (this.logicState == SDKState.open) {
    //     //     this.instance.show();
    //     // }
    //     if (this.resultCallback) {
    //         this.resultCallback(ResultState.YES);
    //         this.resultCallback = null;
    //     }
    // }

    onError() {
        if (this.param.resultCallback) {
            this.param.resultCallback(ResultState.NO);
            this.param.resultCallback = null;
        }
    }

    destroy() {
        if (this.ad) {
            this.ad.offLoad(this.getFunc(this.onLoad))
            this.ad.offError(this.getFunc(this.onError))
            this.ad.destroy();
            this.ad = null;
        }

    }

}